<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->string('no')->unique();
            $table->string('title');
            $table->unsignedBigInteger('user_id')->default(0);
            $table->unsignedBigInteger('product_id')->default(0);
            $table->unsignedBigInteger('product_sku_id')->default(0);
            $table->unsignedBigInteger('amount')->default(0);
            $table->unsignedBigInteger('coupon')->default(0)->comment('优惠券');
            $table->text('address')->nullable();
            $table->unsignedBigInteger('integral')->default(0)->comment('积分');
            $table->decimal('total_amount', 10, 2)->default(0)->comment('订单总金额');
            $table->decimal('pay_amount', 10, 2)->default(0)->comment('实际支付金额');
            $table->string('pay_status')->default('afoot')->comment('支付状态 success fail afoot');
            $table->text('remark')->nullable();
            $table->dateTime('paid_at')->nullable()->comment('支付时间');
            $table->string('payment_method')->nullable()->comment('支付方式wx');
            $table->string('payment_no')->nullable()->comment('支付平台订单号');
            $table->string('refund_status')->nullable()->comment('退款状态');
            $table->string('refund_no')->unique()->nullable()->comment('退款单号');
            $table->boolean('closed')->default(false)->comment('订单是否已关闭');
            $table->string('type')->comment('course课程 node工艺节点 information资料');
            $table->text('extra')->nullable()->comment('其他额外数据');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
};
